package com.business.service.oa;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import com.business.bean.oa.CalendarBean;
import com.business.bean.oa.DispatchWorkBean;
import com.business.bean.oa.ReportDay;
import com.business.bean.system.UserBean;

import net.sf.rose.jdbc.PageBean;
import net.sf.rose.jdbc.dao.BeanDAO;
import net.sf.rose.jdbc.query.BeanSQL;
import net.sf.rose.jdbc.service.Service;
import net.sf.rose.util.DateFormat;

/**
 * 工作调度服务
 */
public class DispatchService {

	/**
	 * 派工申请
	 * 
	 * @param userID - 用户编号
	 * @param date   - 日期
	 */
	public PageBean workApply(Service service, DispatchWorkBean dispatchWork) {
		PageBean res = new PageBean();
		BeanDAO dao = new BeanDAO(service);
		BeanSQL query = dao.getQuerySQL();
		query.setEntityClass(UserBean.class);
		// query.createBatchInsertSql(list);
		dao.batchUpdate();
		return res;
	}

	/**
	 * 获取指定时间段的日历
	 * 
	 * @param dao
	 * @param query
	 * @param departID
	 * @param sDate
	 * @param eDate
	 * @return
	 */
	public List<CalendarBean> getCalendarBeanList(BeanDAO dao, BeanSQL query, String departID, String sDate,
			String eDate) {
		query.setEntityClass(CalendarBean.class);
		query.setSQL("select * from OA_CALENDAR where departID=? and calendarDate>=? and calendarDate<?");
		query.addParameter(departID);
		query.addParameter(sDate);
		query.addParameter(eDate);
		List<CalendarBean> cs = dao.list();
		while (cs.size() == 0 && departID != null && departID.length() > 4) {
			departID = departID.substring(0, departID.length() - 4);
			query.clearParameterList();
			query.addParameter(departID);
			query.addParameter(sDate);
			query.addParameter(eDate);
			cs = dao.list();
		}
		return cs;
	}
}